<template>
    <el-dialog
        class="searchDialog"
        :visible.sync="value"
        title="发票信息查询"
        :before-close="handleClose"
        width="90%"
        append-to-body
        :modal="true"
    >
        <div class="diskInfoWrap">
            <el-form
                :model="searchParams"
                size="small"
                label-width="140px"
                class="formInline"
            >
                <el-row></el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="购买方名称：">
                            <el-input
                                v-model="searchParams.gmfmc"
                                placeholder="请输入"
                            ></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="10">
                        <el-form-item label="发票类型：">
                            <selectCom
                                v-model="searchParams.fplx"

                                :options="[
                                    { label: '数电专票', value: '01' },
                                    { label: '数电普票', value: '02' },
                                    { label: '增值税专用发票', value: '004' },
                                    { label: '增值税普通发票', value: '007' },
                                    { label: '电子普通发票', value: '026' },
                                ]"
                                style="width: 100%"
                            ></selectCom>
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item label="发票号码：">
                            <el-input
                                v-model.trim="searchParams.fphm"
                                placeholder="请输入"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="发票状态：">
                            <!-- :show-option="['0','7','8']" -->
                                        <dict-select v-model="searchParams.fpzt" :dict-code="DictCode.VMS_FPZT" 
                                        :showOption="['0','3','7','8']"
                         style="width: 100%"></dict-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="开票日期：">
                            <el-date-picker
                                v-model="selectDate"
                                type="daterange"
                                align="right"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                @change="onClear"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <div style="float: right">
                            <el-button
                                size="small"
                                type="primary"
                                @click="onSubmit"
                            >
                                查询
                            </el-button>
                            <el-button
                                size="small"
                                type="primary"
                                @click="reset"
                            >
                                重置
                            </el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-form>

            <tableList
                ref="tableRef"
                border
                :heightMin="300"
                :keySet="keySet"
                :tableData="listDetails"
                :paginationShow="true"
                :pageNumber="pages.current"
                :pageSize="pages.size"
                :total="pages.total"
                :radioSelect="true"
                @radioHandleCurrentChange="radioHandleCurrentChange"
                @handleSizeChange="handleSizeChange"
                @handleCurrentChange="handleCurrentChange"
                @rowDblclick="confirm"
            >
                <template #fpzt="{ row }">
                    <div :class="row.fpzt == '正常' ? 'bg' : 'redBG'">
                        {{ row.fpzt }}
                    </div>
                </template>
            </tableList>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="handleClose" size="small">取 消</el-button>
            <el-button type="primary" @click="confirm" size="small">
                确 定
            </el-button>
        </span>
    </el-dialog>
</template>

<script>
import mixinTable from '@/mixin/mtable.js'
import tableList from '@/components/tableList/index.vue'
import selectCom from '@/components/selectCom.vue'
import { currentMonthFirstDayAndLastDay, formaDate } from '@/utils/getTime.js'
import { pageInvoiceSon } from '@/api/matchFlow.js'
import DictSelect from "@/views/invoiceTemplate/components/DictSelect/DictSelect.vue";
import {DictCode} from "@/utils/DictConstant";



export default {
    name: 'searchDialog2',
    mixins: [mixinTable],
      computed: {
    DictCode() {
      return DictCode
    }
  },
    model: {
        prop: 'value',
        event: 'searchCb',
    },
    props: {
        value: {
            type: Boolean,
            default: false,
        },
        lzfphm: {
            type: String,
            default: '',
        },
    },
    data() {
        return {
            selectRow: null,
            dictList: [],
            selectDate: ['', ''],
            listDetails: [],
            keySet: [
                {
                    label: '发票状态',
                    englishName: 'fpzt',
                    isSlot: true,
                    slotName: 'fpzt',
                },
                {
                    label: '发票号码',
                    englishName: 'fphm',
                    width: '200',
                },
                {
                    label: '发票类型',
                    englishName: 'fplx',
                },
                {
                    label: '（购买方）统一社会信用代码/纳税人识别号/身份证件号码',
                    englishName: 'gmfsbh',
                    width: 'labelWidth',
                },
                {
                    label: '购买方名称',
                    width: '300',
                    englishName: 'gmfmc',
                },
                {
                    label: '合计金额',
                    englishName: 'hjje',
                },
                {
                    label: '税额',
                    englishName: 'hjse',
                },
                {
                    label: '价税合计',
                    englishName: 'jshj',
                },
       
                {
                    label: '备注',
                    englishName: 'bz',
                    width: 500,
                },
                {
                    label: '开票日期',
                    englishName: 'kprq',
                    width: 200,
                },
                {
                    label: '数据来源',
                    englishName: 'sjly',
                                        width: 100,
                },
                         {
                    label: '对应红字信息编码',
                    englishName: 'dyhzxxbm',
                    width: 240,
                },
                         {
                    label: '对应蓝字发票号码',
                    englishName: 'dylzfphm',
                    width: 240,
                },
            ],
            lanziOptions: [],
            diaitalEleOptions: [
                { label: '正常', value: '0' },
                { label: '部分红冲', value: '7' },
            ],
            paperOptions: [
                { label: '正常', value: '1' },
                { label: '红冲', value: '3' },
            ],
            searchParams:{
                "fphm": "",
                "fplx": "",
                "fpzt": "",
                "gmfmc": "",
                "kprqq": "",
                "kprqz": "",
 
            },
            pages:{
               "pageNo": 1,
                "pageSize": 10,
                total: 0
            }
        }
    },
    created() {

    },
    mounted() {
        this.getTime()
        this.getList()

    },
    methods: {
        getTime() {
            let { firstDay, LastDay } = currentMonthFirstDayAndLastDay()
            this.selectDate = [ formaDate(firstDay),formaDate(LastDay) ]
        },
        reset() {
            this.searchParams = {
                "fphm": "",
                "fplx": "",
                "fpzt": "",
                "gmfmc": "",
                "kprqq": "",
                "kprqz": "",
            }
            this.getTime()
        },
        confirm() {
            if (this.selectRow === null) {
                return this.$message.warning('请先勾选一条数据！')
            }

            let obj = {
                show: false,
            }
            if (this.selectRow) {
                obj.row = this.selectRow
            }

            this.$emit('searchCb', obj)
        },
        radioHandleCurrentChange(row) {
            this.selectRow = row
        },
        handleClose() {
            let obj = {
                show: false,
            }
            this.$emit('searchCb', obj)
        },
        onClear(val, b) {
            if (val === null) {
                this.selectDate = ['', '']
            }
        },
        onSubmit() {
            this.pages.current = 1
            this.getList()
        },
        async getList() {
            let params = {
                "fphm": this.searchParams.fphm ,
                "fplx": this.searchParams.fplx ,
                "fpzt": this.searchParams.fpzt ,
                "gmfmc": this.searchParams.gmfmc ,
                "kprqq": this.selectDate[0] ,
                "kprqz": this.selectDate[1] ,
                "pageNo": this.pages.pageNo ,
                "pageSize": this.pages.pageSize ,
            }

            pageInvoiceSon(params).then(({ data, code }) => {
                if (code == 200) {
                    this.listDetails = data.records
                    this.pages.total = data.total
                    this.pages.current = data.pages
                    this.pages.size = data.size
                    try {
                        this.$refs.tableRef.$refs.table.setCurrentRow()
                    } catch (error) {}
                }
            })
        },
    },
    components: {
        tableList,
        selectCom,
        DictSelect,
    },
}
</script>

<style lang = "scss" scoped>
::v-deep .el-dialog__body {
    padding-top: 0;
    padding-bottom: 0;
}
.formInline :deep .el-form-item--small {
    margin-bottom: 4px;
}
</style>
